package com.xoa.service.workflow.flowtype.impl;

import java.util.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xoa.dao.WFE.WFEFlowRunPrcsMapper;
import com.xoa.dao.enclosure.AttachmentMapper;
import com.xoa.dao.flowRunFeedback.FlowRunFeedbackMapper;
import com.xoa.dao.flowplugin.FlowPluginMapper;
import com.xoa.dao.workflow.*;
import com.xoa.model.department.Department;
import com.xoa.model.enclosure.Attachment;
import com.xoa.model.flowRunFeedback.FlowRunFeedback;
import com.xoa.model.flowplugin.FlowPluginModel;
import com.xoa.model.users.Users;
import com.xoa.model.workflow.*;
import com.xoa.service.WFE.WFEFactory.WFEFlowProcess;
import com.xoa.service.WFE.WFEFactory.WFEFlowType;
import com.xoa.service.WFE.WFELog.WFELog;
import com.xoa.service.WFE.WFERunner.WFEFlowRun;
import com.xoa.service.WFE.WFERunner.WFEFlowRunInfo;
import com.xoa.service.department.DepartmentService;
import com.xoa.service.users.UsersPrivService;
import com.xoa.service.users.UsersService;
import com.xoa.service.work.WorkService;
import com.xoa.service.work.impl.WorkServiceImpl;
import com.xoa.util.*;
import com.xoa.util.common.L;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.common.wrapper.BaseWrappers;
import org.apache.commons.collections4.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.xoa.service.workflow.flowtype.FlowProcessService;
import com.xoa.util.common.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import sun.security.util.Length;

@Service
public class FlowProcessServiceImpl implements FlowProcessService {

    @Autowired
    private FlowManageLogMapper flowManageLogMapper;

    @Resource
    private FlowProcessMapper flowProcessMapper;

    @Resource
    private DepartmentService departmentService;

    @Resource
    private UsersPrivService usersPrivService;

    @Resource
    private UsersService usersService;

    @Resource
    private FlowTiggerMapper flowTiggerMapper;

    @Resource
    private FlowPluginMapper flowPluginMapper;

    @Resource
    private FlowRunPrcsMapper flowRunPrcsMapper;

    @Resource
    FlowRunFeedbackMapper flowRunFeedbackMapper;

    @Resource
    WorkServiceImpl workService;

    @Autowired
    WFEFlowRunInfo wfeFlowRunInfo;
    @Resource
    WFEFlowRunPrcsMapper WFEFlowRunPrcsMapper;

    @Autowired
    protected WFEFlowType wfeFlowType;


    @Autowired
    protected WFEFlowProcess wfeFlowProcess;

    @Autowired
    private WFELog wfeLog;

    @Autowired
    private WFEFlowRun wfeFlowRun;

    @Autowired
    private AttachmentMapper attachmentMapper;


    @Override
    public FlowProcess find(int id) {
        Map<String, Object> maps = new HashMap<String, Object>();
        maps.put("id", id);
        FlowProcess flowProcess = flowProcessMapper.find(maps);
        return flowProcess;
    }

    /**
     * 创建作者:   张龙飞
     * 创建日期:  2017年5月10日 上午11:18:20
     * 方法介绍:   （修改后保存）在6/3修改补充json解析，并完善已知bug(张勇)
     * 参数说明:
     *
     * @return
     */
    @Override
    @Transactional
    public ToJson<FlowProcess> updateByPrimaryKeySelective(FlowProcess record) {
        ToJson<FlowProcess> tojson = new ToJson<FlowProcess>();
        try {
            L.a("wstemId：" + record.getITEM_ID());
            L.a("autoPrcsUser：" + record.getAUTO_PRCS_USER());
            // 解析页面json串
            String tlement = record.getSettlementOfCondition();
            if (!StringUtils.checkNull(tlement)) {
                String intoTheCondition = JSONArray.parseObject(tlement).getString("intoTheCondition");
                String transferConditions = JSONArray.parseObject(tlement).getString("transferConditions");
               //转入条件逻辑表达式
                if (!StringUtils.checkNull(JSONArray.parseObject(intoTheCondition).getString("list"))) {
                    record.setPrcsIn(JSONArray.parseObject(intoTheCondition).getString("list"));
                }
                //转出条件逻辑表达式 --ym
                if (!StringUtils.checkNull(JSONArray.parseObject(transferConditions).getString("list"))) {
                    record.setPrcsOut(JSONArray.parseObject(transferConditions).getString("list"));
                }
                //转入条件逻辑表达式 --wym
                if (!StringUtils.checkNull(JSONArray.parseObject(intoTheCondition).getString("prcsInSet"))) {
                    record.setPrcsInSet(JSONArray.parseObject(intoTheCondition).getString("prcsInSet"));
                }
                //
                if(!StringUtils.checkNull(JSONArray.parseObject(intoTheCondition).getString("conditionDesc")) && !StringUtils.checkNull(JSONArray.parseObject(transferConditions).getString("conditionDesc"))){
                    String conditions="";
                    if(StringUtils.checkNull(JSONArray.parseObject(intoTheCondition).getString("conditionDesc"))){
                        conditions+="";
                    }else{
                        conditions+=JSONArray.parseObject(intoTheCondition).getString("conditionDesc");
                    }
                    conditions+="\n";
                    if(StringUtils.checkNull(JSONArray.parseObject(transferConditions).getString("conditionDesc"))){
                        conditions+="";
                    }else{
                        conditions+=JSONArray.parseObject(transferConditions).getString("conditionDesc");
                    }
                    record.setConditionDesc(
                            conditions
                    );
                }else if (!StringUtils.checkNull(JSONArray.parseObject(intoTheCondition).getString("conditionDesc"))) {
                    record.setConditionDesc(JSONArray.parseObject(intoTheCondition).getString("conditionDesc"));
                }else  if (!StringUtils.checkNull(JSONArray.parseObject(transferConditions).getString("conditionDesc"))) {
                    record.setConditionDesc("\n"+JSONArray.parseObject(transferConditions).getString("conditionDesc"));
                }
                if (!StringUtils.checkNull(JSONArray.parseObject(transferConditions).getString("prcsOutSet"))) {
                    record.setPrcsOutSet(JSONArray.parseObject(transferConditions).getString("prcsOutSet"));
                }


            }
            // 解析页面json串
            String prcsItem = record.getPrcsItemTwo();
            if (!StringUtils.checkNull(prcsItem)) {
                JSONObject jsonObject = JSONArray.parseObject(prcsItem);
                if(jsonObject!=null){
                    //可写字段串
                    if (!StringUtils.checkNull(jsonObject.getString("prcsItem"))) {
                        record.setPrcsItem(jsonObject.getString("prcsItem"));
                    }
                    //允许在不可写情况下自动赋值的宏控件
                    if (!StringUtils.checkNull(jsonObject.getString("prcsItemAuto"))) {
                        record.setPrcsItemAuto(jsonObject.getString("prcsItemAuto"));
                    }
                    //公共附件中的Office文档详细权限设置：(1-新建权限,2-编辑权限,3-删除权限,4-下载权限,5-打印权限,)',
                    if (!StringUtils.checkNull(jsonObject.getString("attachPriv"))) {
                        record.setAttachPriv(jsonObject.getString("attachPriv"));
                    }
                    //'是否允许本步骤经办人编辑附件(0-不允许,1-允许,)',
                    if (!StringUtils.checkNull(jsonObject.getString("attachEditPriv"))) {
                        record.setAttachEditPriv(jsonObject.getString("attachEditPriv"));
                    }
                    //是否允许本步骤经办人在线创建文档(0-允许,1-不允许,)'
                    if (!StringUtils.checkNull(jsonObject.getString("attachEditPrivOnline"))) {
                        record.setAttachEditPrivOnline(jsonObject.getString("attachEditPrivOnline"));
                    }
                    //宏标记附件上传为图片时展示效果(0-显示图片,1-显示图标和名称,)',
                    if (!StringUtils.checkNull(jsonObject.getString("attachMacroMark"))) {
                        record.setAttachMacroMark(jsonObject.getString("attachMacroMark"));
                    }
                    //是否允许本步骤经办人编辑正文(0-不允许,1-允许,)',
                    if (!StringUtils.checkNull(jsonObject.getString("documentEditPriv"))) {
                        record.setDocumentEditPriv(jsonObject.getInteger("documentEditPriv"));
                    }
                    if (!StringUtils.checkNull(jsonObject.getString("documentEditPrivDetail"))) {
                        record.setDocumentEditPrivDetail(jsonObject.getString("documentEditPrivDetail"));
                    }
                    if (!StringUtils.checkNull(jsonObject.getString("noMainSignerFileYn"))) {
                        record.setNoMainSignerFileYn(jsonObject.getString("noMainSignerFileYn"));
                    }
                }


            }
            if (!StringUtils.checkNull(record.getITEM_ID())) {
                //前端传入参数去除DATA_,data_
                String temp = record.getITEM_ID().replace("DATA_", "").replace("data_", "");;
                record.setAutoUser(temp);
            }
            //判断转交指向下一步骤是否已删除，已删除的prcsId过滤掉
            StringBuffer str=new StringBuffer();
            if(StringUtils.checkNull(String.valueOf(record.getChildFlow()))&&!StringUtils.checkNull(record.getPrcsTo())){
                String[] split = record.getPrcsTo().split(",");
                for (String spl:split
                ) {
                    FlowProcess process = flowProcessMapper.findProcess(record.getFlowId(), record.getPrcsId());
                    if(process!=null){
                        str.append(spl+",");
                    }
                }
                record.setPrcsTo(str.toString());
            }
            /**    李然   添加流程设计的管理日志   ---编辑流程步骤  **/
            HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
            FlowManageLog flowManageLog=wfeLog.getFlowManageLog(request);
            //添加类型
            flowManageLog.setFlowId(flowManageLogMapper.getFlowIdById(record.getId()));
            Map map=new HashMap();
            map.put("id",record.getId());
            //获取一个flowProcess对象
            FlowProcess flowProcess=flowProcessMapper.find(map);
            //添加工作流设计日志--修改
            flowManageLog.setPrcsName(flowProcess.getPrcsName());
            this.insertLog(flowProcess,record,flowManageLog);

            flowProcessMapper.updateByPrimaryKeySelective(record);
            tojson.setFlag(0);
            tojson.setMsg("OK");
        } catch (Exception e) {
            e.printStackTrace();
            tojson.setFlag(1);
            tojson.setMsg("error");
        }
        return tojson;
    }

    @Override
    public List<FlowProcess> findFlowId(int flowId) {
        List<FlowProcess> list = flowProcessMapper.findFlowId(flowId);
        return list;
    }

    /**
     * 创建作者:   张龙飞
     * 创建日期:   2017年5月22日 上午9:44:40
     * 方法介绍:   删除流程
     * 参数说明:   @param id
     *
     * @return void
     */
    @Override
    @Transactional
    public ToJson<FlowProcess> delete(int id, String prcsId, String flowId) {
        ToJson<FlowProcess> toJson = new ToJson<FlowProcess>();
        try {
            // 李然 插入删除步骤工作流程设计日志
            HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
            FlowManageLog flowManageLog=wfeLog.getFlowManageLog(request);
            if(flowId!=null && flowId!=""){
                flowManageLog.setFlowId(Integer.parseInt(flowId));
                String prcsName=flowManageLogMapper.getPrcsName(prcsId, flowId);
                flowManageLog.setPrcsName(prcsName);
            }
            flowManageLog.setType(Constant.DESIGNTYPE13);
            int count=wfeLog.addFlowManageLog(flowManageLog);
            flowProcessMapper.deleteNode(Integer.parseInt(flowId), Integer.parseInt(prcsId));
            flowProcessMapper.deletePrcsId(prcsId+",", flowId);
            toJson.setFlag(0);
            toJson.setMsg("ok");
        } catch (Exception e) {
            toJson.setFlag(1);
            toJson.setMsg("error");
        }
        return toJson;
    }


    @Override
    @Transactional(readOnly = true)
    public ToJson<FlowProcessList> flowView(Integer flowId,Integer runId,String userId) {
        ToJson<FlowProcessList> toJson = new ToJson(1,"error");
        try {
            Map<String, String> map = null;
            //定义
            List<Map<String, String>> lm = new ArrayList<Map<String, String>>();
            //根据flowId获取流程信息
            List<FlowProcess> list = flowProcessMapper.findF(flowId);
            for (FlowProcess flowProcess : list){
                String autoUserOpName = usersService.findUsersByuid(flowProcess.getAutoUserOp());
                String autoUserName = usersService.findUsersByuid(flowProcess.getAutoUser());
                flowProcess.setAutoUserName(autoUserName);
                flowProcess.setAutoUserOpName(autoUserOpName);
            }
            List<FlowRunPrcs> runPrcsList =  flowRunPrcsMapper.selectAllByRunId(runId);
            int len = list.size();
            //f.setFlowName(list.get(0).getFlowName());
            list.get(len - 1).setSetType("end round");
            list.get(0).setSetType("start");
            for (int i = 0; i < len; i++) {
                Integer prId = list.get(i).getPrcsId();
                String prceTo = list.get(i).getPrcsTo();
                if (StringUtils.checkNull(prceTo)) {
                    map = new HashMap<String, String>();
                    map.put("from", Integer.toString(prId));
                    if (i < len - 1) {
                        if (list.get(i + 1).getPrcsId() == prId + 1) {
                            map.put("to", Integer.toString(list.get(i + 1).getPrcsId()));
                        }
                    } else {
                        map.put("to", "end");
                    }
                    lm.add(map);
                } else {
                    String[] p = prceTo.split(",");
                    for (String a : p) {
                        if(!"0".equals(a)) {
                            map = new HashMap<String, String>();
                            map.put("from", Integer.toString(prId));
                            map.put("to", a.toString());
                            lm.add(map);
                        }else {
                            map = new HashMap<String, String>();
                            map.put("from", Integer.toString(prId));
                            map.put("to", "end");
                            list.get(i).setSetType("end round");
                            lm.add(map);
                        }
                    }
                }
            }
            //汉字转换方法
            List<FlowProcess> listp = this.returnChinese(list);
            //定义用于返回的流程信息
            FlowProcessList flowProcessList = new FlowProcessList();
            flowProcessList.setConnections(lm);
            flowProcessList.setDesigndata(listp);
            flowProcessList.setMax(listp.size());
            flowProcessList.setFlowRunPrcsList(runPrcsList);
            toJson.setObject(flowProcessList);
            toJson.setFlag(0);
            toJson.setMsg("ok");
        }catch (Exception e){
            L.e("FlowProcessServiceImpl flowView:"+e);
        }
        return toJson;
    }

    @Override
    @Transactional
    public ToJson<FlowProcess> insertSelective(FlowProcess record) {
        ToJson<FlowProcess> toJson = new ToJson<FlowProcess>();
        try {
            FlowProcess fp = wfeFlowProcess.getFpByPrcsId(record.getFlowId(), record.getPrcsId());
            if (fp != null){
                toJson.setFlag(1);
                toJson.setMsg("该流程步骤已存在，请修改");
            }else{
                flowProcessMapper.insert(record);
                //判断上一步骤是否有指向，如果没有自动连接下一步骤
                FlowProcess lastFp = wfeFlowProcess.getFpByPrcsId(record.getFlowId(), record.getPrcsId()-1);
                if (lastFp!=null&&StringUtils.checkNull(lastFp.getPrcsTo())){
                    lastFp.setPrcsTo(record.getPrcsId()+",");
                    flowProcessMapper.updateTopAndLeft(lastFp);
                }
                toJson.setFlag(0);
                toJson.setMsg("ok");
                //toJson.setObject(record);

                /**    李然   添加新建流程步骤的管理日志     **/
                HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
                FlowManageLog flowManageLog=wfeLog.getFlowManageLog(request);
                flowManageLog.setType(Constant.DESIGNTYPE4);
                flowManageLog.setFlowId(record.getFlowId());
                flowManageLog.setPrcsName(record.getPrcsName());
                wfeLog.addFlowManageLog(flowManageLog);
            }

        } catch (Exception e) {
            toJson.setFlag(1);
            toJson.setMsg("error");
            e.printStackTrace();
        }
        return toJson;
    }

    @Override
    public FlowProcess findbyprcsId(int flowId, int prcsId) {
        Map<String, Object> maps = new HashMap<String, Object>();
        maps.put("folwId", flowId);
        maps.put("prcsId", prcsId);
        FlowProcess flowProcess = flowProcessMapper.findbyprcsId(maps);
        return flowProcess;
    }


    /**
     * 创建作者:   张勇
     * 创建日期:   2017/6/3 11:24
     * 方法介绍:   修改流程节点坐标
     * 参数说明:
     *
     * @return
     */
    @Override
    @Transactional
    public ToJson<FlowProcess> updateTopAndLeft(FlowProcess flowProcess) {
        ToJson<FlowProcess> toJson = new ToJson<FlowProcess>();
        FlowProcess prcsTo = flowProcessMapper.findLine(flowProcess.getId());
        try {
            if (StringUtils.checkNull(flowProcess.getPrcsTo())){
                flowProcessMapper.updateLeftTop(flowProcess);
            }else{
                String prcsToI = prcsTo.getPrcsTo();
                StringBuffer prcsTo1 = new StringBuffer(prcsToI);
                String[] prcsToId = flowProcess.getPrcsTo().split(",");
                int len = prcsToId.length;
                for (int i = 0; i < len; i++) {
                    if (!prcsToI.contains(prcsToId[i])) {
                        prcsTo1.append(prcsToId[i] + ",");
                    }
                }
                flowProcess.setPrcsTo(prcsTo1.toString());

                flowProcessMapper.updateTopAndLeft(flowProcess);
            }

           /* if (prcsTo.getPrcsTo().equals("0") || prcsTo.getPrcsTo().equals("0,")) {
                flowProcessMapper.updateTopAndLeft(flowProcess);
            } else if (StringUtils.checkNull(prcsTo.getPrcsTo())) {
                if (flowProcess.getPrcsTo().equals("")) {
                    flowProcess.setPrcsTo((prcsTo.getPrcsId() + 1) + ",");
                    flowProcessMapper.updateTopAndLeft(flowProcess);
                }else {
                    flowProcessMapper.updateTopAndLeft(flowProcess);
                }
            }
            if (prcsTo.getPrcsTo() != "") {
                String prcsToI = prcsTo.getPrcsTo();
                StringBuffer prcsTo1 = new StringBuffer(prcsToI);
                String[] prcsToId = flowProcess.getPrcsTo().split(",");
                int len = prcsToId.length;
                for (int i = 0; i < len; i++) {
                    if (!prcsToI.contains(prcsToId[i])) {
                        prcsTo1.append(prcsToId[i] + ",");
                    }
                }
                flowProcess.setPrcsTo(prcsTo1.toString());
                flowProcessMapper.updateTopAndLeft(flowProcess);
            }*/
            toJson.setFlag(0);
            toJson.setMsg("ok");
            //查询步骤id与步骤名称
            FlowProcess flowProcess1 = flowProcessMapper.selectPrcsIdPrcsName(flowProcess.getId());
            String[] string = flowProcess.getPrcsTo().split(",");
            String strings=string[string.length-1];
            //FlowProcess flowProcess2 = flowProcessMapper.selectPrcsIdPrcsNames(flowProcess1.getFlowId(), Integer.parseInt(strings));
            /**    工作流程设计日志添加---节点连线     **/
            if(strings != null && strings.length() != 0) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                FlowManageLog flowManageLog = wfeLog.getFlowManageLog(request);
                flowManageLog.setType(Constant.DESIGNTYPE23);
                flowManageLog.setFlowId(flowProcess1.getFlowId());
                flowManageLog.setPrcsName(flowProcess1.getPrcsId() + "→" + strings);
                wfeLog.addFlowManageLog(flowManageLog);
            }
        } catch (Exception e) {
            toJson.setTotleNum(1);
            toJson.setMsg(e.getMessage());
        }
        return toJson;
    }

    /**
     * 部门id转换为部门名字
     *
     * @param name
     * @return
     */
    public String deptName(String name) {
        String deptName = null;
//        getDeptNameById
        return deptName;
    }

    /**
     * 创建作者:   张勇
     * 创建日期:   2017/6/8 17:30
     * 方法介绍:   连接线删除
     * 参数说明:
     * @return
     */
    @Override
    @Transactional
    public ToJson<FlowProcess> findPrcessLine(FlowProcess flowProcesse,String toPrcsLine){
        ToJson<FlowProcess> toJson = new ToJson<FlowProcess>();
        FlowProcess flowProcess = flowProcessMapper.findPrcessLine(flowProcesse.getFlowId(),flowProcesse.getPrcsId());
        FlowProcess fpr = new FlowProcess();
        try {
            if (StringUtils.checkNull(flowProcess.getPrcsTo())) {
                fpr.setId(flowProcess.getId());
                fpr.setPrcsTo("0");
                flowProcessMapper.updateTopAndLeft(fpr);
            } else {
                String[] prcsTo = flowProcess.getPrcsTo().split(",");
                int leng = prcsTo.length;
                if (leng == 1) {
                    fpr.setId(flowProcess.getId());
                    fpr.setPrcsTo("");
                    flowProcessMapper.updateTopAndLeft(fpr);
                } else {
                    String names = "";
                    for (int i = 0; i < leng; i++) {
                        String prcsToI = prcsTo[i];
                        if (!prcsToI.equals(toPrcsLine)) {
                            names += (prcsToI + ",");
                        }
                    }
                    fpr.setId(flowProcess.getId());
                    fpr.setPrcsTo(names);
                    flowProcessMapper.updateTopAndLeft(fpr);
                }
            }
            toJson.setFlag(0);
            toJson.setMsg("ok");
            //查询步骤id与步骤名称
            FlowProcess flowProcess1 = flowProcessMapper.selectPrcsIdPrcsName(flowProcess.getId());
            /**    工作流程设计日志添加---删除连线     **/
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            FlowManageLog flowManageLog = wfeLog.getFlowManageLog(request);
            flowManageLog.setType(Constant.DESIGNTYPE22);
            flowManageLog.setFlowId(flowProcess1.getFlowId());
            flowManageLog.setPrcsName(flowProcesse.getPrcsId()+"→"+toPrcsLine);
            wfeLog.addFlowManageLog(flowManageLog);
        }catch (Exception e){
            toJson.setFlag(1);
            toJson.setMsg("error");
            L.e("Process findPrcessLine:"+e);
        }
        return toJson;
    }

    /**
     * 创建作者:   张勇
     * 创建日期:   2017/7/13 10:58
     * 方法介绍:   触发器执行方式和触发节点哈希表
     * 参数说明:
     * @return
     */
    public Map<Object,String> returnTiggerValue(){
        Map<Object,String> maps = new HashMap<Object,String>();
        // 执行方式
        maps.put("BEFORE_FRONTEND","前台,执行操作前");
        maps.put("AFTER_FRONTEND","前台,执行操作后");
        maps.put("BEFORE_BACKEND","后台,执行操作前");
        maps.put("AFTER_BACKEND","后台,执行操作后");

        // 触发节点
        maps.put("CREATE","新建操作");
        maps.put("RECEIVE","接收操作");
        maps.put("SAVE","保存操作");
        maps.put("TURN","转交操作");
        maps.put("INTRUST","委托操作");
        maps.put("BACK","退回操作");

        // 查询插件名字放到哈希表
        List<FlowPluginModel> list = flowPluginMapper.showFlowPlugin();
        if(list.size() > 0) {
            for (FlowPluginModel flp : list) {
                maps.put(flp.getFlowPluginId(), flp.getFlowPluginName());
            }
        }
        return maps;
    }

    /**
     * 创建作者:   张勇
     * 创建日期:   2017/7/14 13:21
     * 方法介绍:    我经办的步骤
     * 参数说明:  flowId 流程ID  prcsId 流程步骤
     * @return
     */
    @Override
    @SuppressWarnings("all")
    public ToJson myFlowView(Integer flowId,Integer runId,String userId) {
        ToJson toJson = new ToJson(1,"error");
        try {
            Map<String, String> map = null;
            //定义
            List<Map<String, String>> lm = new ArrayList<Map<String, String>>();
            //根据flowId获取流程信息
            List<FlowProcess> list = flowProcessMapper.findF(flowId);
            List<FlowRunPrcs> runPrcsList =  flowRunPrcsMapper.selectMyAll(userId,runId);
            int listLength = list.size();
            int runPrcsListLenth = runPrcsList.size();
            //处理下标
            if(listLength>runPrcsListLenth){
                for(int i = listLength-1 ; i >= runPrcsListLenth ; i--){
                    list.remove(i);
                }
            }
            Date newDate = new Date();
            for(int i = 0 ; i < runPrcsListLenth ; i ++){
                Integer prId = list.get(i).getPrcsId();
                String prceTo = list.get(i).getPrcsTo();
                if (StringUtils.checkNull(prceTo)) {
                    map = new HashMap<String, String>();
                    map.put("from", Integer.toString(prId));
                    if (i < runPrcsListLenth - 1) {
                        if (list.get(i + 1).getPrcsId() == prId + 1) {
                            map.put("to", Integer.toString(list.get(i + 1).getPrcsId()));
                        }
                    }else {
                        map.put("to", "end");
                    }
                    lm.add(map);
                } else {
                    String[] p = prceTo.split(",");
                    for (String a : p) {
                        if(!"0".equals(a)) {
                            map = new HashMap<String, String>();
                            map.put("from", Integer.toString(prId));
                            map.put("to", a.toString());
                            lm.add(map);
                        }else {
                            map = new HashMap<String, String>();
                            map.put("from", Integer.toString(prId));
                            map.put("to", "end");
                            list.get(i).setSetType("end round");
                            lm.add(map);
                        }
                    }
                }
                // 处理时间和姓名转换
                runPrcsList.get(i).setUserName(usersService.getUserNameById(runPrcsList.get(i).getUserId()));

                if(DateFormat.getTime(runPrcsList.get(i).getPrcsTime()) != -621701856) {
                    // 工作接收时间
                    runPrcsList.get(i).setReceive(DateFormat.getStrTime(DateFormat.getTime(runPrcsList.get(i).getPrcsTime())));
                    // 办理停留时间
                    runPrcsList.get(i).setHandleTime(DateFormat.returnTime((DateFormat.getTime(DateFormat.getStrDate(newDate)))-DateFormat.getTime(runPrcsList.get(i).getPrcsTime())));
                }
                //计算时间转换
                if(DateFormat.getTime(runPrcsList.get(i).getPrcsTime()) != -621701856 && runPrcsList.get(i).getPrcsId()>1 ||
                        DateFormat.getTime(runPrcsList.get(i).getPrcsTime()) == -621701856 && runPrcsList.get(i).getPrcsId()>1){
                    Integer runIds = runPrcsList.get(i).getRunId();
                    String prcsUser= runPrcsList.get(i).getUserId();
                    Integer prcsId = runPrcsList.get(i).getPrcsId()-1;
                    Map<String,Object> params =new HashMap<String,Object>();
                    params.put("userId",prcsUser);
                    params.put("prcsId", prcsId);
                    params.put("runId", runId);
                    String upTime = flowRunPrcsMapper.findTimeBy(params);
                    if(!StringUtils.checkNull(upTime)) {
                        // 到达时间
                        runPrcsList.get(i).setReceiptTime(DateFormat.getStrTime(DateFormat.getTime(upTime)));
                        // 到达停留时间
                        runPrcsList.get(i).setArriveTime(DateFormat.returnTime((DateFormat.getTime(DateFormat.getStrDate(newDate))) - DateFormat.getTime(runPrcsList.get(i).getReceiptTime())));
                    }
                }else {
                    runPrcsList.get(i).setReceiptTime(DateFormat.getStrTime(DateFormat.getTime(runPrcsList.get(i).getPrcsTime())));
                    runPrcsList.get(i).setArriveTime(DateFormat.returnTime((DateFormat.getTime(DateFormat.getStrDate(newDate))) - DateFormat.getTime(runPrcsList.get(i).getPrcsTime())));
                    runPrcsList.get(i).setReceive("");
                    runPrcsList.get(i).setHandleTime("");
                }
            }

            // 转换为汉字
            List<FlowProcess> listp =this.returnChinese(list);
            //定义用于返回的流程信息
            FlowProcessList flowProcessList = new FlowProcessList();
            flowProcessList.setConnections(lm);
            flowProcessList.setDesigndata(listp);
            flowProcessList.setMax(listp.size());
            flowProcessList.setFlowRunPrcsList(runPrcsList);
            toJson.setFlag(0);
            toJson.setMsg("ok");
            toJson.setObject(flowProcessList);
        }catch (Exception e){
            L.e("FlowProcessServiceImpl myFlowView:"+e);
        }
        return toJson;
    }

    @Override
    public ToJson getFlowAttachment(Integer runId,String company,Users users) {
        ToJson<Attachment> json = new ToJson<Attachment>();
        try {
            //判断权限
            String attachPriv = flowProcessMapper.getAttachPrivByrunId(runId,users.getUserId());
            if (!StringUtils.checkNull(attachPriv)){
                String attachPrivArray[] = attachPriv.split(",");
                List<String> list =new ArrayList<String>();
                for(String s : attachPrivArray){
                    if(!list.contains(s))
                        list.add(s);
                }
                attachPriv= org.apache.commons.lang3.StringUtils.join(list, ",");
            }else{
                attachPriv="";
            }
            FlowRun flowRun = wfeFlowRun.find(runId);
            String viewUser =flowRun.getViewUser();
            if (Arrays.asList(viewUser.split(",")).contains(users.getUserId())){
                attachPriv="1,2,3,4,5";
            }
            
            //定义用于存储附件信息的集合
            List<Attachment> attachmentList = new ArrayList<Attachment>();

            if (flowRun.getAttachmentId() != "" || flowRun.getAttachmentName() != "") {
                String attachmentId[] = flowRun.getAttachmentId().split(",");
                String attachmenName[] = flowRun.getAttachmentName().split("\\*");
                for (int i = 0; i < attachmentId.length; i++) {
                    String aid = attachmentId[i].substring(0, attachmentId[i].indexOf('@'));
                    String ym = attachmentId[i].substring(attachmentId[i].indexOf('@') + 1, attachmentId[i].indexOf('_'));
                    String attachId;
                    String fileSize = "";
                    String time = "";
                    if (attachmentId[i].contains("*")) {
                        attachId = attachmentId[i].substring(attachmentId[i].indexOf('_') + 1, attachmentId[i].indexOf('*'));
                        fileSize = attachmentId[i].substring(attachmentId[i].indexOf('*') + 1, attachmentId[i].indexOf('|'));
                        time = attachmentId[i].substring(attachmentId[i].indexOf('|') + 1, attachmentId[i].length());
                    } else {
                        attachId = attachmentId[i].substring(attachmentId[i].indexOf('_') + 1, attachmentId[i].length());
                    }
                  /*  String attachId = attachmentId[i].substring(attachmentId[i].indexOf('_') + 1, attachmentId[i].indexOf('*'));
                    String fileSize = attachmentId[i].substring(attachmentId[i].indexOf('*') + 1, attachmentId[i].indexOf('|'));
                    String time = attachmentId[i].substring(attachmentId[i].indexOf('|') + 1, attachmentId[i].length());*/


                    Attachment attachment = attachmentMapper.selectByPrimaryKey(Integer.parseInt(aid));
                    if (attachment == null) {
                        attachment = new Attachment();
                        String attachName = attachmenName[i];
                        String attUrl = "AID=" + aid + "&" + "MODULE=" + ModuleEnum.WORKFLOW.getName() + "&" + "COMPANY=" + company + "&" +
                                "YM=" + ym + "&" + "ATTACHMENT_ID=" + attachId + "&" + "ATTACHMENT_NAME=" + attachName;
                        attachment.setAid(Integer.parseInt(aid));
                        attachment.setYm(ym);
                        attachment.setAttachId(attachId);
                        attachment.setAttachName(attachName);
                        attachment.setAttUrl(attUrl);
                        attachment.setFileSize(fileSize);
                        attachment.setTime(time);
                        attachment.setATTACH_PRIV(attachPriv);
                        attachmentList.add(attachment);
                    } else {
                        String attUrl = "AID=" + aid + "&" + "MODULE=" + ModuleEnum.WORKFLOW.getName() + "&" + "COMPANY=" + company + "&" +
                                "YM=" + ym + "&" + "ATTACHMENT_ID=" + attachment.getAttachId() + "&" + "ATTACHMENT_NAME=" + attachment.getAttachName();
                        attachment.setAttUrl(attUrl);
                        attachment.setFileSize(attachment.getSize());
                        attachment.setTime(time);
                        attachment.setATTACH_PRIV(attachPriv);
                        attachmentList.add(attachment);
                    }

                }
            }
            json.setObj(attachmentList);
            json.setFlag(0);
            json.setMsg("OK");

        } catch (Exception e) {
            L.e("findworkUpload" + e);
            json.setFlag(1);
            json.setMsg(e.getMessage());
        }
        return json;
    }

    @Override
    public ToJson selectFlowFeedBackByRunId(String runId,String userId) {
      /*  List<FlowRunFeedback> datas = flowRunFeedbackMapper.selectFlowFeedBackByRunId(runId);
        for (FlowRunFeedback flowRunFeedback : datas){
            flowRunFeedback.setEditTime(flowRunFeedback.getEditTime().substring(0,flowRunFeedback.getEditTime().length()-2));
        }*/
        ToJson json =new ToJson();
        try{
            //通过run_id查询
            List<FlowRunPrcs> flowRunPrcsList = WFEFlowRunPrcsMapper.findMaxFrp(Integer.parseInt(runId));
            Integer prcsId =null;
            Integer flowPrcs = null;
            if(flowRunPrcsList.size()>0){
                prcsId = flowRunPrcsList.get(0).getPrcsId();
                flowPrcs = flowRunPrcsList.get(0).getFlowPrcs();
            }
            FlowTypeModel flowTypeModel = wfeFlowType.sfTbyrunId(Integer.parseInt(runId));
            String flowType = flowTypeModel.getFlowType();
            Integer flowId = flowTypeModel.getFlowId();
            //获取所有流程步骤
            List<FlowRunFeedback> modelList = selFlowFeedBackByRunId(runId);
            //固定流程
            if (flowType.equals("1")) {
                //获取该流程所有步骤
                List<FlowProcess> allFp = wfeFlowProcess.findFlowId(flowId);
                for (FlowProcess flowProcess : allFp) {
                    //处理不是当前节点的会签可见性
                    if (!String.valueOf(flowProcess.getPrcsId()).equals(flowPrcs)) {
                        //针对其他步骤不可见
                        if (flowProcess.getSignlook().equals("2")) {
                            Iterator<FlowRunFeedback> it = modelList.iterator();
                            while (it != null && it.hasNext()) {
                                FlowRunFeedback fbm = it.next();
                                if (fbm.getFlowPrcs() == flowProcess.getPrcsId()) {
                                    it.remove();
                                }
                            }
                        }
                    } else {//处理是当前节点的会签可见性
                        if (flowProcess.getSignlook().equals("1")) {//本步骤经办人之间不可见
                            Iterator<FlowRunFeedback> it = modelList.iterator();
                            while (it != null && it.hasNext()) {
                                FlowRunFeedback fbm = it.next();
                                if (fbm.getFlowPrcs() == flowProcess.getPrcsId() &&  !userId.equals(fbm.getUserId())) {
                                    it.remove();
                                }
                            }
                        }
                    }
                }
            }
            for (FlowRunFeedback flowRunFeedback : modelList) {
                Users users = usersService.findUsersByuserId(flowRunFeedback.getUserId());
                String editTime = flowRunFeedback.getEditTime().substring(0, flowRunFeedback.getEditTime().length() - 2);
                flowRunFeedback.setEditTime(editTime);
                flowRunFeedback.setUsers(users);
            }
            // 排序 按照步骤号进行排序
            modelList.sort(new Comparator<FlowRunFeedback>() {
                @Override
                public int compare(FlowRunFeedback o1, FlowRunFeedback o2) {
                    if(o1.getPrcsId()>o2.getPrcsId()){
                        return 1;
                    }
                    return 0;
                }
            });

            json.setObj(modelList);
            json.setMsg("OK");
            json.setFlag(0);
        } catch (Exception e) {
            json.setFlag(0);
            json.setMsg("false");
        }
        return json;
    }




    @Override
    public BaseWrappers getFlowRunPrecsAll(String runId) {
        BaseWrappers wrappers=new BaseWrappers();
        wrappers.setStatus(true);
        if(StringUtils.checkNull(runId)){
            wrappers.setFlag(false);
            wrappers.setMsg("失败");
            return wrappers;
        }
        List<FlowRunPrcs> datas=flowRunPrcsMapper.getFlowRunReacsAllByRunId(runId);
        Date newDate = new Date();
        for(FlowRunPrcs runPrcs:datas){
            if (Integer.parseInt(runPrcs.getPrcsFlag())<=2){
                // 到达时间
                runPrcs.setArriveTime(DateFormat.returnTime((DateFormat.getTime(DateFormat.getStrDate(newDate)))-DateFormat.getTime(runPrcs.getCreateTime())));
                // 办理时长
                if (DateFormat.getTime(runPrcs.getPrcsTime()) == -621701856){
                    runPrcs.setHandleTime("未接收");
                    runPrcs.setPrcsTime("");
                }else {
                    runPrcs.setHandleTime(DateFormat.returnTime((DateFormat.getTime(DateFormat.getStrDate(newDate)))-DateFormat.getTime(runPrcs.getPrcsTime())));

                }
            }else {
                // 到达时间
                try{
                    runPrcs.setArriveTime(DateFormat.returnTime((DateFormat.getTime(runPrcs.getDeliverTime())) - DateFormat.getTime(runPrcs.getCreateTime())));
                }catch (NumberFormatException e){
                    runPrcs.setArriveTime("");
                }
                //办理时间
                try{
                    runPrcs.setHandleTime(DateFormat.returnTime((DateFormat.getTime(runPrcs.getDeliverTime()))-DateFormat.getTime(runPrcs.getPrcsTime())));
                }catch (NumberFormatException e){
                    runPrcs.setHandleTime("");
                }
            }
            runPrcs.setCreateTime(runPrcs.getCreateTime().substring(0,runPrcs.getCreateTime().length()-2));
            if (!StringUtils.checkNull(runPrcs.getPrcsTime())){
                runPrcs.setPrcsTime(runPrcs.getPrcsTime().substring(0,runPrcs.getPrcsTime().length()-2));
            }
            if (!StringUtils.checkNull(runPrcs.getDeliverTime())){
                runPrcs.setDeliverTime(runPrcs.getDeliverTime().substring(0,runPrcs.getDeliverTime().length()-2));
            }
        }

        Map<Integer, List<FlowRunPrcs>> map = new HashMap<Integer, List<FlowRunPrcs>>();
        List<FlowRunPrcs> flowRunPrcsList = null;
        for (FlowRunPrcs flowRunPrcs : datas){
            if (map.keySet().contains(flowRunPrcs.getPrcsId())){
                flowRunPrcsList = map.get(flowRunPrcs.getPrcsId());
                flowRunPrcsList.add(flowRunPrcs);
            }else {
                flowRunPrcsList = new ArrayList<FlowRunPrcs>();
                flowRunPrcsList.add(flowRunPrcs);
                map.put(flowRunPrcs.getPrcsId(), flowRunPrcsList);
            }
        }
        //1是结束，0是未结束
        List<FlowRunPrcs> list = map.get(map.size());
        for (FlowRunPrcs flowRunPrcs : list){
            if (Integer.parseInt(flowRunPrcs.getPrcsFlag())<4){
                wrappers.setStatus(false);
            }
        }
        wrappers.setDatas(datas);
        wrappers.setFlag(true);
        wrappers.setMsg("0k");
        return wrappers;
    }

    /**
     * 创建作者:   张勇
     * 创建日期:   2017/7/14 13:32
     * 方法介绍:   流程设计器返回汉字方法
     * 参数说明:   传递FlowProcess list参数
     * @return
     */
    public List<FlowProcess> returnChinese(List<FlowProcess> list){
        List<FlowProcess> listp = new ArrayList<FlowProcess>();
        //添加汉字转换方法
        for (FlowProcess flowProcess : list) {
            if (!StringUtils.checkNull(flowProcess.getPrcsDept())) {
                //lr+
                if(flowProcess.getPrcsDept().equals("ALL_DEPT")){
                    flowProcess.setPrcsDeptName("全部部门");
                }else {//lr+ else{

                    flowProcess.setPrcsDeptName(departmentService.getDeptNameByDeptId(flowProcess.getPrcsDept(), ","));
                    flowProcess.setPrcsDeptNo(departmentService.getDeptNoByDeptId(flowProcess.getPrcsDept(), ","));
                }//lr+else}  else里的数据不是lr加的，是原数据不能删
            }
            if (!StringUtils.checkNull(flowProcess.getPrcsPriv())) {
                flowProcess.setPrcsPrivName(usersPrivService.getPrivNameByPrivId(flowProcess.getPrcsPriv(), ","));
            }
            if (!StringUtils.checkNull(flowProcess.getPrcsUser())) {
                flowProcess.setPrcsUserName(usersService.getUserNameById(flowProcess.getPrcsUser()));
                //flowProcess.setPrcsUserPriv(usersService.getUserPrivById(flowProcess.getPrcsUser()));
            }
            List<FlowTiggerModel> flowTiggerModel = flowTiggerMapper.selectFlowTigger(flowProcess.getFlowId(),flowProcess.getPrcsId());
            if(flowTiggerModel != null && flowTiggerModel.size() >0 ){
                List<FlowTiggerModel> fltm = new ArrayList<FlowTiggerModel>();
                for(FlowTiggerModel ftm : flowTiggerModel){
                    ftm.setPluginTypeName(returnTiggerValue().get(ftm.getPluginType()));
                    ftm.setPluginWayName(returnTiggerValue().get(ftm.getPluginWay()));
                    ftm.setPluginName(returnTiggerValue().get(ftm.getPlugin()));
                    fltm.add(ftm);
                }
                flowProcess.setFlowTiggerModel(fltm);
            }else {
                flowProcess.setFlowTiggerModel(new ArrayList<FlowTiggerModel>());
            }
            listp.add(flowProcess);
        }
        return listp;
    }
    public List<FlowRunFeedback> selFlowFeedBackByRunId(String runId) {
        FlowTypeModel flowTypeModel = wfeFlowType.sfTbyrunId(Integer.parseInt(runId));
        String flowType = flowTypeModel.getFlowType();
        Integer flowId = flowTypeModel.getFlowId();
        List<FlowRunFeedback> list = new ArrayList<FlowRunFeedback>();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("runId", Integer.parseInt(runId));
        //如果是自由流程
        if (flowType.equals("2")) {
            list = flowRunFeedbackMapper.selectRunId(map);
        } else {
            list = flowRunFeedbackMapper.selectFlowFeedBackByRunId(runId);
        }
        return list;
    }


    private void insertLog(FlowProcess flowProcess,FlowProcess record,FlowManageLog flowManageLog) {
        //编辑数据
        List basicListflowProcess = new ArrayList();
        List basicListRecord = new ArrayList();
        //更新流程步骤:经办人
        List updateAgentListflowProcess = new ArrayList();
        List updateAgentListRecord = new ArrayList();
        //更新流程步骤:智能选人
        List updateCapacityListflowProcess = new ArrayList();
        List updateCapacityListRecord = new ArrayList();
        //更新流程步骤:流转设置
        List updateStreamListflowProcess = new ArrayList();
        List updateStreamListRecord = new ArrayList();
        //设置流程步骤可写字段
        List settingListflowProcess = new ArrayList();
        List settingListRecord = new ArrayList();
        //设置流程步骤保密字段
        List setting2ListflowProcess = new ArrayList();
        List setting2ListRecord = new ArrayList();
        //设置流程步骤必填字段
        List setting3ListflowProcess = new ArrayList();
        List setting3ListRecord = new ArrayList();

        //基本设置
        basicListflowProcess.add(flowProcess.getPrcsId());
        basicListflowProcess.add(flowProcess.getPrcsType());
        basicListflowProcess.add(flowProcess.getPrcsName());
        basicListflowProcess.add(flowProcess.getPrcsTo());

        //经办人
        updateAgentListflowProcess.add(flowProcess.getPrcsUser());
        updateAgentListflowProcess.add(flowProcess.getPrcsDept());
        updateAgentListflowProcess.add(flowProcess.getPrcsPriv());
        updateAgentListflowProcess.add(flowProcess.getSignType());
        updateAgentListflowProcess.add(flowProcess.getCountersign());

        //智能选人
        updateCapacityListflowProcess.add(flowProcess.getAutoType());
        updateCapacityListflowProcess.add(flowProcess.getUserFilter());

        //流转设置
        updateStreamListflowProcess.add(flowProcess.getTopDefault());
        updateStreamListflowProcess.add(flowProcess.getUserLock());
        updateStreamListflowProcess.add(flowProcess.getFeedback());
        updateStreamListflowProcess.add(flowProcess.getSignlook());
        updateStreamListflowProcess.add(flowProcess.getTurnPriv());
        updateStreamListflowProcess.add(flowProcess.getAllowBack());
        updateStreamListflowProcess.add(flowProcess.getSyncDeal());
        updateStreamListflowProcess.add(flowProcess.getGatherNode());
        updateStreamListflowProcess.add(flowProcess.getViewPriv());



        //可写字段
        settingListflowProcess.add(flowProcess.getPrcsItem());
        settingListflowProcess.add(flowProcess.getDocumentEditPriv());
        settingListflowProcess.add(flowProcess.getPrcsItemAuto());
        settingListflowProcess.add(flowProcess.getAttachPriv());
        settingListflowProcess.add(flowProcess.getAttachEditPriv());
        settingListflowProcess.add(flowProcess.getAttachEditPrivOnline());
        settingListflowProcess.add(flowProcess.getAttachMacroMark());

        //保密字段
        setting2ListflowProcess.add(flowProcess.getHiddenItem());

        //必填字段
        setting3ListflowProcess.add(flowProcess.getRequiredItem());
        //条件设置
       /* updateListflowProcess.add(flowProcess.getPrcsIn());
        updateListflowProcess.add(flowProcess.getPrcsOut());
        updateListflowProcess.add(flowProcess.getPrcsInSet());
        updateListflowProcess.add(flowProcess.getPrcsOutSet());*/
        /*----------------------------------------------------------------------------------*/
        //基本设置
        basicListRecord.add(record.getPrcsId());
        basicListRecord.add(record.getPrcsType());
        basicListRecord.add(record.getPrcsName());
        basicListRecord.add(record.getPrcsTo());

        //经办人
        updateAgentListRecord.add(record.getPrcsUser());
        updateAgentListRecord.add(record.getPrcsDept());
        updateAgentListRecord.add(record.getPrcsPriv());
        updateAgentListRecord.add(record.getSignType());
        updateAgentListRecord.add(record.getCountersign());

        //智能选人
        updateCapacityListRecord.add(record.getAutoType());
        updateCapacityListRecord.add(record.getUserFilter());

        //流转设置
        updateStreamListRecord.add(record.getTopDefault());
        updateStreamListRecord.add(record.getUserLock());
        updateStreamListRecord.add(record.getFeedback());
        updateStreamListRecord.add(record.getSignlook());
        updateStreamListRecord.add(record.getTurnPriv());
        updateStreamListRecord.add(record.getAllowBack());
        updateStreamListRecord.add(record.getSyncDeal());
        updateStreamListRecord.add(record.getGatherNode());
        updateStreamListRecord.add(record.getViewPriv());

        //可写字段
        settingListRecord.add(record.getPrcsItem());
        settingListRecord.add(record.getDocumentEditPriv());
        settingListRecord.add(record.getPrcsItemAuto());
        settingListRecord.add(record.getAttachPriv());
        settingListRecord.add(record.getAttachEditPriv());
        settingListRecord.add(record.getAttachEditPrivOnline());
        settingListRecord.add(record.getAttachMacroMark());

        //保密字段
        setting2ListRecord.add(record.getHiddenItem());

        //必填字段
        setting3ListRecord.add(record.getRequiredItem());
        //条件设置
       /* updateListRecord.add(record.getPrcsIn());
        updateListRecord.add(record.getPrcsOut());
        updateListRecord.add(record.getPrcsInSet());
        updateListRecord.add(record.getPrcsOutSet());*/

       //判断基本设置编辑
       for(int i=0;i<basicListRecord.size();i++){
           if(!(basicListRecord.get(i)+"").equals((basicListflowProcess.get(i)+""))){
               flowManageLog.setType(Constant.DESIGNTYPE11);
               wfeLog.addFlowManageLog(flowManageLog);
               break;
           }
       }
       //判断经办人
       for (int i=0;i<updateAgentListflowProcess.size();i++){
           if(!(updateAgentListflowProcess.get(i)+"").equals((updateAgentListRecord.get(i)+""))){
               flowManageLog.setType(Constant.DESIGNTYPE8);
               wfeLog.addFlowManageLog(flowManageLog);
               break;
           }
       }
       //判断智能选人
       for (int i=0;i<updateCapacityListRecord.size();i++){
           if(!(updateCapacityListRecord.get(i)+"").equals((updateCapacityListflowProcess.get(i)+""))){
               flowManageLog.setType(Constant.DESIGNTYPE9);
               wfeLog.addFlowManageLog(flowManageLog);
               break;
           }
       }
       //判断流转设置
       for (int i=0;i<updateStreamListRecord.size();i++){
           if(!(updateStreamListRecord.get(i)+"").equals((updateStreamListflowProcess.get(i)+""))){
               flowManageLog.setType(Constant.DESIGNTYPE10);
               wfeLog.addFlowManageLog(flowManageLog);
               break;
           }
       }
       //判断可写字段
       for (int i=0;i<settingListRecord.size();i++){
           if(!(settingListRecord.get(i)+"").equals((settingListflowProcess.get(i)+""))){
               flowManageLog.setType(Constant.DESIGNTYPE5);
               wfeLog.addFlowManageLog(flowManageLog);
               break;
           }
       }
       //判断保密字段
       for (int i=0;i<setting2ListRecord.size();i++){
           if(!(setting2ListRecord.get(i)+"").equals((setting2ListflowProcess.get(i)+""))){
               flowManageLog.setType(Constant.DESIGNTYPE6);
               wfeLog.addFlowManageLog(flowManageLog);
               break;
           }
       }
       //判断必填字段
       for (int i=0;i<setting3ListRecord.size();i++){
           if(!(setting3ListRecord.get(i)+"").equals((setting3ListflowProcess.get(i)+""))){
               flowManageLog.setType(Constant.DESIGNTYPE7);
               wfeLog.addFlowManageLog(flowManageLog);
               break;
           }
       }


    }
    /**
    * @创建作者:李然  Lr
    * @方法描述：获取子流程
    * @创建时间：14:00 2018/9/7

    **/
    @Override
    public ToJson getSonFlow(Integer flowId,Integer prcsId) {
        ToJson toJson=new ToJson();
        List<FlowProcess> flowProcess=flowProcessMapper.getPrcsIdAndPrcsName(flowId,prcsId);
        Map<String,Object> mapUser=new HashMap<>();
        if(flowProcess!=null){
            for(int i=0;i<flowProcess.size();i++){
                mapUser.put("flowId",flowId);
                mapUser.put("prcsId",flowProcess.get(i).getPrcsId());
            }
            toJson.setObj(flowProcess);
            toJson.setFlag(0);
            toJson.setMsg("ok");
        }else{
            toJson.setFlag(1);
            toJson.setMsg("null");
        }
        return toJson;
    }
}
